const url = 'https://ydsplat.sportgoing.com/clubmanager'
const fetch = require('./fetch')

/**
 * @param  {String} type   类型，例如：'GET'
 * @param  {String} api    参数
 * @param  {Objece} option  参数
 */
function fetchApi(type, api, sessionId, option) {
    return fetch(url, type, api, option, sessionId)
}


module.exports = {

    pageIndex: 1,
    pageSize: 8,

    /**
     * 获取session接口,识别用户
     * @param  {String} code   类型，例如：'xxxxxxxxx'
     */

    getSession: function(option) {
        return fetchApi('GET', 'weChatApp/getSession?code=' + option).then(res => res.data)
    },

    /**
     * 获取用户信息接口.暂且保留,以便将来做app时存入用户数据
     */

    getUserInfo: function(sessionId){
        return fetchApi('GET', 'ptUser/getUserInfo', sessionId).then(res => res.data)
    },

    /**
     * 修改并保存用户信息
     */
    
    setUserInfo: function(option, sessionId){
    	return fetchApi('POST', 'ptUser/saveOrUpdate', sessionId, option).then(res => res.data)	
    },

    /**
     * 获取可用的卡券
     */
    
    getPtCouponAvailableCount: function(sessionId){
        return fetchApi('GET', 'ptCoupon/getPtCouponAvailableCount', sessionId).then(res => res.data) 
    },

    /**
     * 获取我的收藏场馆列表
     */
    
    getCollectionList: function(sessionId){
        return fetchApi('GET', 'PtCollection/getCollectionList', sessionId).then(res => res.data) 
    },

    /**
     * 场馆详情
     */
    
    getClubDetailInfo: function(clubId){
        return fetchApi('GET', `bsClub/club/${clubId}`).then(res => res.data) 
    },

    /**
     * 收藏场馆
     */
    
    collection: function(clubId, sessionId){
        return fetchApi('POST', `PtCollection/collection/${clubId}`, sessionId).then(res => res.data) 
    },

    /**
     * 取消场馆收藏
     */
    
    cancelCollection: function(id, sessionId){
        return fetchApi('POST', `PtCollection/cancelCollection/${id}`, sessionId).then(res => res.data) 
    },

    /**
     * 获取活动列表 
     */
    
    getActivityList: function(sessionId){
        return fetchApi('GET', `ptCouponProject/getProjectList?pageIndex=${this.pageIndex}&pageSize=${this.pageSize}`, sessionId).then(res => res.data)    
    },

    /**
     * 领取活动抵扣劵
     */
    
    getCoupon: function(option, sessionId){
        return fetchApi('POST', 'ptCoupon/receive', sessionId, option).then(res => res.data)    
    },  

    /**
     * 我的卡券列表
     */
    
    getCouponList: function(sessionId){
        return fetchApi('GET', `ptCoupon/getPtCouponList?pageIndex=${this.pageIndex}&pageSize=${this.pageSize}`, sessionId).then(res => res.data)    
    },

    /**
     * 获取场馆列表
     */
    
    getClubList : function(type, sortType, lat, lng){
        return fetchApi('GET', `bsClub/getClubList?pageIndex=${this.pageIndex}&pageSize=${this.pageSize}&type=${type}&sortType=${sortType}&lat=${lat}&lng=${lng}`).then(res => res.data)    
    },

    /**
     * 获取运动类型
     */
    
    getPbSportTypeByClubId: function(clubId){
        return fetchApi('GET', `ticket/getPbSportTypeByClubId/${clubId}`).then(res => res.data)    
    },

    /**
     * 获取场馆对应时间可购买的票券
     */
    getBuyTickets: function(clubId,date,type){
        return fetchApi('GET', `ticket/getTicket?clubId=${clubId}&date=${date}&type=${type}`).then(res => res.data)    
    },

     /**
     * 下订单
     */
    submitTicketOrder: function(clubId,orderInfo,sessionId){
        return fetchApi('POST', `weChatApp/order/submitTicketOrder?clubId=${clubId}`,sessionId,orderInfo).then(res => res.data)
    },

    /**
     * 订单确认支付
     */
    submitTicketOrderPay: function(clubId,orderInfo,sessionId){
        return fetchApi('POST', `weChatApp/order/payTicketOrder?clubId=weChatApp`,sessionId,orderInfo).then(res => res.data)
    },

    /**
     * 获取优惠票券
     */
    getptCoupon: function(date,type,sessionId){
        return fetchApi('GET', `ptCoupon/getPtCouponAvailable?date=${date}&type=${type}`,sessionId).then(res => res.data)
    },

    /**
     * 订单列表
     */
    
    getOrderList: function(status, sessionId){
        return fetchApi('GET', `weChatApp/order/getOrderList?pageIndex=${this.pageIndex}&pageSize=${this.pageSize}&status=${status}`,sessionId).then(res => res.data)
    },
 
    /**
     * 是否收藏场馆
     */
    
    isCollection: function(clubId, sessionId){
        return fetchApi('GET', `PtCollection/isCollection/${clubId}`,sessionId).then(res => res.data)
    },
    /**
     * 订单详情
     */
    getOrderDetial: function(orderCode, sessionId){
        return fetchApi('GET', `weChatApp/order/getOrderDetail/${orderCode}`,sessionId).then(res => res.data)
    }

}